package www.ld.com.config;

import org.hibernate.validator.HibernateValidator;
import org.hibernate.validator.HibernateValidatorConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.validation.Validation;
import javax.validation.Validator;
@Configuration
@ConditionalOnClass(value = HibernateValidatorConfiguration.class)
public class ValidatorConfiguration {
    @Bean
    public Validator validator(){
        Validator validator = Validation.byProvider( HibernateValidator.class )
                .configure()
                .addProperty( "hibernate.validator.fail_fast", "true" )
                .buildValidatorFactory()
                .getValidator();
        return validator;
    }
}
